package org.example.panel.datapanel;
import javax.swing.*;
import java.awt.event.*;
import org.example.operation.*;

/**
 * @author lenovo
 */

public class ClearDataPanel extends JPanel {
    public ClearDataPanel(){
        //组件准备
        JButton clearCourse = new JButton("清空课程");
        JButton clearStudent = new JButton("清空学生");
        JButton clearScore = new JButton("清空成绩");
        Box box = Box.createHorizontalBox();
        //注册监视器
        clearCourse.addActionListener((ActionEvent e)->{
            CourseOperation.clearCourse();
            JOptionPane.showMessageDialog(null,
                    "清空课程成功", null, JOptionPane.WARNING_MESSAGE);
        });
        clearStudent.addActionListener((ActionEvent e)->{
            StudentOperation.clearStudent();
            JOptionPane.showMessageDialog(null,
                    "清空学生成功", null, JOptionPane.WARNING_MESSAGE);
        });
        clearScore.addActionListener((ActionEvent e)->{
            ScoreOperation.clearScore();
            JOptionPane.showMessageDialog(null,
                    "清空成绩成功", null, JOptionPane.WARNING_MESSAGE);
        });
        //添加组件
        box.add(clearCourse);
        box.add(Box.createHorizontalStrut(5));
        box.add(clearStudent);
        box.add(Box.createHorizontalStrut(5));
        box.add(clearScore);
        add(box);
    }
}
